﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace Arztmodul
{
    /// <summary>
    /// Version: 1.1
    ///  Author: Jan Baltzer
    ///    Date: 2012-06-15
    /// form to show patients vitalData as lineChart or table
    /// </summary>
    public partial class Show : Form
    {
        //class properties
        private Patient patient;
        private IPersistDoc persi;

        /// <summary>
        /// constructor to inizialize show
        /// </summary>
        /// <param name="patient"> patient to show </param>
        /// <param name="persi"> persistance interface to work with </param>
        public Show(Patient patient, IPersistDoc persi)
        {
            InitializeComponent();

            this.persi = persi;
            this.patient = patient;
            this.Text = "Einsehen (" + patient.firstName + " " + patient.name + ")";
            initializeLineChart();
            initializeGridView();
        }

        /// <summary>
        /// initializes lineChart
        /// </summary>
        private void initializeLineChart()
        {
            Series[] lines;
            int i;

            //get lines
            if (persi.patientExists(patient))
            {
                //print lines
                lines = persi.getVitalDataChart(patient);
                for (i = 0; i < lines.Length; i++)
                {
                    vitalDataChart.Series.Add(lines[i]);
                    vitalDataChart.Series[i].ChartType = SeriesChartType.Line;
                }
            }
            else
            {
                //show warning
                MessageBox.Show(HCSWarnings.MESSAGE_BOX_WARNING_NO_DATABASE, HCSWarnings.MESSAGE_BOX_WARNING_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        /// <summary>
        /// initializes gridView
        /// </summary>
        private void initializeGridView()
        {
            object[] lines;
            string[] headLine;
            int i;

            //get lines
            if ((lines = persi.getVitalDataGrid(patient)) != null)
            {
                //get header
                headLine = (string[]) lines[0];

                //set lenght
                vitalDataGridView.ColumnCount = headLine.Length;

                //set headline
                for (i = 0; i < headLine.Length; i++)
                {
                    vitalDataGridView.Columns[i].Name = headLine[i];
                }

                //set lines
                for (i = 1; i < lines.Length; i++)
                {
                    vitalDataGridView.Rows.Add((string[])lines[i]);
                }
            }
            else
            {
                //show warning
                MessageBox.Show(HCSWarnings.MESSAGE_BOX_WARNING_NO_DATABASE, HCSWarnings.MESSAGE_BOX_WARNING_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        
        /// <summary>
        /// routine to handle vitalDataChart_Click event
        /// </summary>
        /// <param name="sender">sender of event</param>
        /// <param name="e">event</param>
        private void vitalDataChart_Click(object sender, EventArgs e)
        {
            //change view
            vitalDataChart.Hide();
            vitalDataGridView.Show();
        }

        /// <summary>
        /// routine to handle vitalDataGridView_Click event
        /// </summary>
        /// <param name="sender">sender of event</param>
        /// <param name="e">event</param>
        private void vitalDataGridView_Click(object sender, EventArgs e)
        {
            vitalDataGridView.Hide();
            vitalDataChart.Show();
        }
    }
}
